//
//  SetUpCell.m
//  Courses
//
//  Created by YiXuePxh on 15/5/28.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "SetUpCell.h"

@implementation SetUpCell{
    UIImageView*    _image;
    UILabel*        _txtLabel;
    UISwitch*       _switch;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _image = [[UIImageView alloc]initWithFrame:AutoRectMake(5, 15, 50, 50, WTFAutoLayoutTypeText)];
        [self.contentView addSubview:_image];
        [_image setTransform:CGAffineTransformMakeScale(0.5, 0.5)];
        _txtLabel = [[UILabel alloc]initWithFrame:AutoRectMake(50, 27, DEFAULT_WIDTH - 100, 25, WTFAutoLayoutTypeText)];
        [self.contentView addSubview:_txtLabel];
        _switch = [[UISwitch alloc]initWithFrame:AutoRectMake(DEFAULT_WIDTH - 65, 25, 51, 31,WTFAutoLayoutTypeText)];
        NSLog(@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"wifiControl"]);
        BOOL wifiControl = [[[NSUserDefaults standardUserDefaults]objectForKey:@"wifiControl"]boolValue];
        [_switch setOn:wifiControl];
        [_switch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:_switch];
    }
    return self;
}
-(void)setImageName:(NSString *)imageName{
    _image.image = [UIImage imageNamed:imageName];
}
-(void)setText:(NSString *)text{
    _txtLabel.font = [UIFont fontWithName:@"" size:20];
    _txtLabel.text = text;
}
-(void)setSwicthTag:(NSInteger *)swicthTag{
    
}
-(void)switchAction:(UISwitch* )sender{
    if (sender.isOn) {
        NSLog(@"isOn");
        [[NSUserDefaults standardUserDefaults]setBool:true forKey:@"justWifi"];
        [[NSUserDefaults standardUserDefaults]setBool:true forKey:@"wifiControl"];
    }else{
        NSLog(@"isOff");
        [[NSUserDefaults standardUserDefaults]setBool:false forKey:@"justWifi"];
        [[NSUserDefaults standardUserDefaults]setBool:false forKey:@"wifiControl"];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
